package JDBC;

import java.sql.*;
import java.util.*;
import javax.naming.*;
import javax.sql.DataSource;

public class ConnPoolTest {
	public static void main(String str[]) throws Exception {
		Connection con = null;
		Statement st = null;
		ResultSet rs = null;
		try {
			Properties p = new Properties();
			p.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
			p.setProperty("java.naming.provide.url", "localhost:1099");
			p.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming");
			Context ctx = new InitialContext(p);
			Object obj = ctx.lookup("JLCJNDI");
			DataSource ds = (DataSource) obj;
			con = ds.getConnection();
			rs = st.executeQuery("select * from user_info");
			while (rs.next()) {
				System.out.println(rs.getInt(1) + "\t" + rs.getString(2) + "\t" + rs.getLong(3));
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (rs != null)
				rs.close();
			if (st != null)
				st.close();
			if (con != null)
				con.close();
		}
	}
}